import { NestFactory } from '@nestjs/core';

import { AppModule } from './app.module';
import { LoggerMiddleware } from './common/middlewares/http-log';
import { AllExceptionsFilter } from './common/filters/http-exception.filter';
import { ResponseInterceptor } from './common/insterceptors/response.interceptor';

// import { BullAdapter } from 'bull-board/bullAdapter';
// import { createBullBoard } from 'bull-board';
// import { Queue } from 'bull';
// import { getQueueToken } from '@nestjs/bull';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.use(LoggerMiddleware);
  app.useGlobalFilters(new AllExceptionsFilter());
  app.useGlobalInterceptors(new ResponseInterceptor());

  // 任务队列页面查看
  // const mailQueue = app.get<Queue>(getQueueToken('mail'));
  // const { router } = createBullBoard([new BullAdapter(mailQueue)]);
  // app.use('/admin/queues', router);

  await app.listen(process.env.PORT ?? 3000);
}

bootstrap().catch((err) => {
  console.error(err);
  process.exit(1);
});
